package com.nts.bupna.generator;

import static com.nts.bupna.util.StringUtil.cap;

import java.util.Iterator;

import com.google.common.base.Splitter;

final class CopyUtil {
    static Splitter dot = Splitter.on('.');

    private CopyUtil() {// prevent constr.
    }

    static boolean simple(final String expr) {
        return expr.indexOf('.') < 0;
    }

    static String toSetter(final String to) {
        final Iterator<String> tokens = dot.split(to).iterator();
        final StringBuilder res = new StringBuilder(tokens.next());
        String token = tokens.next();
        while (tokens.hasNext()) {
            res.append(".get" + cap(token) + "()");
            token = tokens.next();
        }
        res.append(".set" + cap(token));
        return res.toString();
    }

    static String toGetter(final String from) {
        if (simple(from)) {
            return from;
        }
        final Iterator<String> tokens = dot.split(from).iterator();
        final StringBuilder res = new StringBuilder(tokens.next());
        while (tokens.hasNext()) {
            res.append(".get" + cap(tokens.next()) + "()");
        }
        return res.toString();
    }
}